package jobs;

// 玩具类
class Toy {
    private String bodyMaterial;
    private int wheelCount;
    private String decoration;

    public void setBodyMaterial(String bodyMaterial) {
        this.bodyMaterial = bodyMaterial;
    }
    public void setWheelCount(int wheelCount) {
        this.wheelCount = wheelCount;
    }
    public void setDecoration(String decoration) {
        this.decoration = decoration;
    }

    @Override
    public String toString() {
        return "Toy{" +
                "bodyMaterial='" + bodyMaterial + '\'' +
                ", wheelCount=" + wheelCount +
                ", decoration='" + decoration + '\'' +
                '}';
    }
}

// 抽象建造者
abstract class ToyBuilder {
    protected Toy toy = new Toy();
    public abstract void buildBodyMaterial();
    public abstract void buildWheelCount();
    public abstract void buildDecoration();
    public Toy getToy() {
        return toy;
    }
}

// 具体建造者：机器人玩具
class RobotToyBuilder extends ToyBuilder {
    @Override
    public void buildBodyMaterial() {
        toy.setBodyMaterial("金属");
    }
    @Override
    public void buildWheelCount() {
        toy.setWheelCount(0); // 机器人无轮子
    }
    @Override
    public void buildDecoration() {
        toy.setDecoration("LED灯+天线");
    }
}

// 具体建造者：汽车玩具
class CarToyBuilder extends ToyBuilder {
    @Override
    public void buildBodyMaterial() {
        toy.setBodyMaterial("塑料");
    }
    @Override
    public void buildWheelCount() {
        toy.setWheelCount(4);
    }
    @Override
    public void buildDecoration() {
        toy.setDecoration("赛车贴纸");
    }
}

// 指挥者
class ToyDirector {
    private ToyBuilder builder;
    public ToyDirector(ToyBuilder builder) {
        this.builder = builder;
    }
    public void constructToy() {
        builder.buildBodyMaterial();
        builder.buildWheelCount();
        builder.buildDecoration();
    }
}

// 测试类
public class ToyTest {
    public static void main(String[] args) {
        // 组装机器人玩具
        ToyBuilder robotBuilder = new RobotToyBuilder();
        ToyDirector director1 = new ToyDirector(robotBuilder);
        director1.constructToy();
        Toy robotToy = robotBuilder.getToy();
        System.out.println("机器人玩具: " + robotToy);

        // 组装汽车玩具
        ToyBuilder carBuilder = new CarToyBuilder();
        ToyDirector director2 = new ToyDirector(carBuilder);
        director2.constructToy();
        Toy carToy = carBuilder.getToy();
        System.out.println("汽车玩具: " + carToy);
    }
}
